<head>
	<meta charset="utf-8">

	<link href="../css/styles.css" rel="stylesheet">
	<link rel="stylesheet" href="../css/bootstrap.min.css" type="text/css">
	<link rel="stylesheet" href="../css/font-awesome.min.css" type="text/css">
	<link rel="stylesheet" href="../css/themify-icons.css" type="text/css">
	<link rel="stylesheet" href="../css/elegant-icons.css" type="text/css">
	<link rel="stylesheet" href="../css/owl.carousel.min.css" type="text/css">
	<link rel="stylesheet" href="../css/nice-select.css" type="text/css">
	<link rel="stylesheet" href="../css/jquery-ui.min.css" type="text/css">
	<link rel="stylesheet" href="../css/slicknav.min.css" type="text/css">
	<link rel="stylesheet" href="../css/style.css" type="text/css">
	<link rel="stylesheet" href="../css/susu.css" type="text/css">
	<!-- Js Plugins -->
	<script src="../js/jquery-3.3.1.min.js"></script>
	<script src="../js/bootstrap.min.js"></script>
	<script src="../js/jquery-ui.min.js"></script>
	<script src="../js/jquery.countdown.min.js"></script>
	<script src="../js/jquery.nice-select.min.js"></script>
	<script src="../js/jquery.zoom.min.js"></script>
	<script src="../js/jquery.dd.min.js"></script>
	<script src="../js/jquery.slicknav.js"></script>
	<script src="../js/owl.carousel.min.js"></script>
</head>
<body >

<!--头部引入-->
<div class="su_head ">
</div>


<br />

		<div id="main-wrapper">
	<section class="gray pt-5 pb-5">
		<div class="container-fluid">
			<div class="row">
				<div class="col-lg-3 col-md-4 col-sm-12">
					<div class="property_dashboard_navbar">
						<div class="dash_user_avater">
							<img src="#" class="img-fluid avater" alt="" id="avater">
							<h4 id="avatername">姓名</h4>
						</div>
						<div class="dash_user_menues">
							<ul>
					
								<li ><a href="mypersonal.html"><i class="fa fa-user-tie"></i>个人信息</a></li>
								<li><a href="mycart.html"><i class="fa fa-bookmark"></i>我的收藏<span class="notti_coun style-2">7</span></a></li>
								<li><a href="myorder.html"><i class="fa fa-tasks"></i>我的交易</a></li>

								<li><a href="myinfo.html"><i class="fa fa-tasks"></i>我的发布</a></li>
								<li><a href="mypublish.html"><i class="fa fa-pen-nib"></i>发布信息</a></li>
								<li class="active"><a href="mypassword.html"><i class="fa fa-unlock-alt"></i>修改密码</a></li>
							</ul>
						</div>
						<div class="dash_user_footer">
							<ul>
								<li><a href="#"><i class="fa fa-power-off"></i></a></li>
								<li><a href="#"><i class="fa fa-comment"></i></a></li>
								<li><a href="#"><i class="fa fa-cog"></i></a></li>
							</ul>
						</div>
					</div>
				</div>
			
						<div class="col-lg-9 col-md-8">
							<div class="dashboard-body">
								<div class="dashboard-wraper">
									<div class="frm_submit_block">
										<h4>修改密码</h4>
										<div class="frm_submit_wrap">
											<div class="form-row">
												<div class="form-group col-lg-12 col-md-6">
													<label>旧密码</label><input type="password" class="form-control" id="oldpassword">
												</div>
												<div class="form-group col-md-6"><label>新密码</label>
													<input type="password" class="form-control" id="newpassword"></div>
												<div class="form-group col-md-6"><label>确认密码</label>
													<input type="password" class="form-control" id="surepassword"></div>
												<div class="form-group col-md-6 ">
													<div class="alert alert-danger hidden"  role="alert">
													</div>
												</div>
												<div class="form-group col-lg-12 col-md-12">
													<button class="btn btn-theme" type="button" onclick="editpassword()">修改</button></div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
		</div>
	</body>
	<script type="text/javascript">


		//调用公共头部
		$('.su_head').load('head.html');
		//获取导航栏信息
		$(document).ready(function () {
			$.ajax({
				type: 'get',
				url: '/ayuancity/categorys/getcategoryAndtype',
				success: function (res) {
					// console.log( $('.su_nav').text())
					for (let i = 0; i < res.content.data.length; i++) {

						let nav = res.content.data[i];
						var category =
								`
							<li id="${nav.categoryName}">
							<a href="itemsPage.html?categoryName=${nav.categoryName}">${nav.categoryName}</a>
							`;
						var drop = '';
						var type = '';
						if (nav.types.length > 0) {
							drop = ` <ul class="dropdown "  >`
							for (let j = 0; j < nav.types.length; j++) {
								type = type + `<li ><a href="itemsPage.html?categoryName=${nav.categoryName}&typeName=${nav.types[j].typeName}">${nav.types[j].typeName}</a></li>`

							}
							type = type + `</ul>`
						}
						var template = category + drop + type + ` </li>`;
						$('.su_nav').append(template);

					}
					// console.log($('.su_head').text());
				}

			})
			// 判断是否登录 已登录 显示昵称
			let citytoken = sessionStorage.getItem('citytoken');
			if (citytoken) {
				$.ajax({
					type: 'GET',
					url: '/city/user/info',
					data: {
						token: citytoken
					},
					success: function (json) {
						if (json.success) {
							let username = json.content.user.userName;
							let userId=json.content.user.userId;
							sessionStorage.setItem('userId',userId);
							// console.log(json)
							$('#yuan-login').html(username);
							// $('#user-showname').html(showname);
							$('#yuan-login').attr('data-toggle', 'dropdown');
							$('#yuan-userImg').removeClass("hidden");
							$('#yuan-userImg').removeClass("hidden");
							$('#yuan-userImg').attr("src",json.content.user.userImg);
							$('#avater').attr("src",json.content.user.userImg)
							$('#avatername').html(json.content.user.userName);
						}
					}
				});
			}
		});

		//修改密码
		function  editpassword(){
			let oldpassword=$('#oldpassword').val();
			let newpassword=$('#newpassword').val();
			let surepassword=$('#surepassword').val();
			if (newpassword==null || newpassword==''){
				$('.alert-danger').html('新密码不能为空!')
				$('.alert-danger').removeClass('hidden')
			}else if (newpassword !=surepassword){
				$('.alert-danger').html('密码不一致!')
				$('.alert-danger').removeClass('hidden')
			}else{
				$.ajax({
					type: 'post',
					url: '/ayuancity/users/editUserPwd',
					data: {
						userId: sessionStorage.getItem('userId'),
						oldpwd: oldpassword,
						newpwd:newpassword
					},
					success:function (res) {
						if (res.success){
							alert('修改密码成功')
							location.href = 'login.html';
						}else {
							alert(res.content.message)
						}
					}
				})
			}
		}

		function loginout() {
			$.ajax({
				type: 'POST',
				url: '/city/user/OutLogin',
				success: function (json) {
					if (json.success) {
						sessionStorage.removeItem('citytoken');
						sessionStorage.removeItem("userId")
						alert("欢迎下次登录")
						location.href = 'index.html';
					}
				}
			});
		}
	</script>
</html>
